<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>uniCloud云开发使用教程 | 小何blog (记录美好)</title><meta name="keywords" content="uniCloud,云开发"><meta name="author" content="六根清静"><meta name="copyright" content="六根清静"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="学习JavaScript之前要先搞清楚计算机基础，分清与HTML等标记语言的区别，这样能更好的帮我们学习JavaScript">
<meta property="og:type" content="article">
<meta property="og:title" content="uniCloud云开发使用教程">
<meta property="og:url" content="https://liugenqingjing2.coding.me/2021/01/30/uniCloud%E4%BA%91%E5%BC%80%E5%8F%91%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/index.html">
<meta property="og:site_name" content="小何blog (记录美好)">
<meta property="og:description" content="学习JavaScript之前要先搞清楚计算机基础，分清与HTML等标记语言的区别，这样能更好的帮我们学习JavaScript">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/Vx4Zi@ef8@Ro.jpg">
<meta property="article:published_time" content="2021-01-30T02:15:05.000Z">
<meta property="article:modified_time" content="2021-01-30T12:55:08.169Z">
<meta property="article:author" content="六根清静">
<meta property="article:tag" content="uniCloud">
<meta property="article:tag" content="云开发">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/Vx4Zi@ef8@Ro.jpg"><link rel="shortcut icon" href="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200907/wOu*ZmuVb5A4.png"><link rel="canonical" href="https://liugenqingjing2.coding.me/2021/01/30/uniCloud%E4%BA%91%E5%BC%80%E5%8F%91%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin="crossorigin"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?e829919a4d931d733ee74d5d97a51582";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap"><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":20,"languages":{"author":"作者: 六根清静","link":"链接: ","source":"来源: 小何blog (记录美好)","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  ClickShowText: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  justifiedGallery: {
    js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
    css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
  },
  isPhotoFigcaption: true,
  islazyload: true,
  isanchor: true
};

var saveToLocal = {
  set: function setWithExpiry(key, value, ttl) {
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-01-30 20:55:08'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
   if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }
  const autoChangeMode = '2'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
   if (asideStatus === 'hide') {
     document.documentElement.classList.add('hide-aside')
   } else {
     document.documentElement.classList.remove('hide-aside')
   }
}})()</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/HCLonely/images@master/others/heartbeat.min.css"><link rel="stylesheet" href="/css/shuo.css"/><link rel="stylesheet" href="/magnetcss/magnet.css"/><link rel="stylesheet" href="/css/calendar.css"/><link rel="stylesheet" href="//at.alicdn.com/t/font_2060620_l0j6b710zk.css"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/font-awesome-animation.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/macblack.css"><link rel="stylesheet" href="/css/change.css"><link rel="stylesheet" href="/news/css/news.css"/><style type="text/css">#toggle-sidebar {bottom: 80px}</style><link rel="stylesheet" href="/magnet/css/catalogMagnet.css"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-double-row-display@1.00/cardlistpost.css"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/iconfont.min.css"><link rel="stykesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/pool.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/><link rel="stylesheet" href="/zan/zan.css"><link rel="stylesheet" href="/swiper/swiper.min.css"><link rel="stylesheet" href="/swiper/swiperstyle.css"><style>#article-container.post-content h1:before, h2:before, h3:before, h4:before, h5:before, h6:before { -webkit-animation: avatar_turn_around 1s linear infinite; -moz-animation: avatar_turn_around 1s linear infinite; -o-animation: avatar_turn_around 1s linear infinite; -ms-animation: avatar_turn_around 1s linear infinite; animation: avatar_turn_around 1s linear infinite; }</style><meta name="generator" content="Hexo 5.0.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="wizard-scene"><div class="wizard-objects"><div class="wizard-square"></div><div class="wizard-circle"></div><div class="wizard-triangle"></div></div><div class="wizard"><div class="wizard-body"></div><div class="wizard-right-arm"><div class="wizard-right-hand"></div></div><div class="wizard-left-arm"><div class="wizard-left-hand"></div></div><div class="wizard-head"><div class="wizard-beard"></div><div class="wizard-face"><div class="wizard-adds"></div></div><div class="wizard-hat"><div class="wizard-hat-of-the-hat"></div><div class="wizard-four-point-star --first"></div><div class="wizard-four-point-star --second"></div><div class="wizard-four-point-star --third"></div></div></div></div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="http://01.027cgb.com/632500/1576904533264.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">138</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">63</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/stars/"><i class="fa-fw fas fa-star faa-shake animated-hover"></i><span> 收藏网址</span></a></div><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-zhuye faa-shake animated-hover"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog.html"><i class="fa-fw iconfont icon-Artboard faa-shake animated-hover"></i><span> 博客</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-guidang faa-shake animated-hover"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian faa-shake animated-hover"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw iconfont icon-yule1"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/movies/"><i class="fa-fw iconfont icon-yingshi faa-shake animated-hover"></i><span> 影视</span></a></li><li><a class="site-page" href="/games/"><i class="fa-fw iconfont icon-youxi1 faa-shake animated-hover"></i><span> 游戏</span></a></li><li><a class="site-page" href="/galleryGroup"><i class="fa-fw iconfont icon-tuku faa-shake animated-hover"></i><span> 图库</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/messagepad/"><i class="fa-fw iconfont icon-ziyuan6 faa-shake animated-hover"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-icon_xinyong_xianxing_jijin- faa-shake animated-hover"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-guanyuwomen faa-shake animated-hover"></i><span> 关于我</span></a></div></div></div></div><div id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/Vx4Zi@ef8@Ro.jpg)"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">小何blog (记录美好)</a></span><span id="menus"><div id="search_button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/stars/"><i class="fa-fw fas fa-star faa-shake animated-hover"></i><span> 收藏网址</span></a></div><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-zhuye faa-shake animated-hover"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog.html"><i class="fa-fw iconfont icon-Artboard faa-shake animated-hover"></i><span> 博客</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-guidang faa-shake animated-hover"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian faa-shake animated-hover"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw iconfont icon-yule1"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/movies/"><i class="fa-fw iconfont icon-yingshi faa-shake animated-hover"></i><span> 影视</span></a></li><li><a class="site-page" href="/games/"><i class="fa-fw iconfont icon-youxi1 faa-shake animated-hover"></i><span> 游戏</span></a></li><li><a class="site-page" href="/galleryGroup"><i class="fa-fw iconfont icon-tuku faa-shake animated-hover"></i><span> 图库</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/messagepad/"><i class="fa-fw iconfont icon-ziyuan6 faa-shake animated-hover"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-icon_xinyong_xianxing_jijin- faa-shake animated-hover"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-guanyuwomen faa-shake animated-hover"></i><span> 关于我</span></a></div></div><span class="close" id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></span></span></nav><div id="post-info"><h1 class="post-title">uniCloud云开发使用教程</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-01-30T02:15:05.000Z" title="发表于 2021-01-30 10:15:05">2021-01-30</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-01-30T12:55:08.169Z" title="更新于 2021-01-30 20:55:08">2021-01-30</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%89%8D%E7%AB%AF%E5%AD%A6%E4%B9%A0/">前端学习</a></span></div><div class="meta-secondline"> <span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.4k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>8分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="uniCloud云开发使用教程："><a href="#uniCloud云开发使用教程：" class="headerlink" title="uniCloud云开发使用教程："></a>uniCloud云开发使用教程：</h1><blockquote>
<p><strong>uniapp之云开发uniCloud入门官方: <a target="_blank" rel="noopener" href="https://unicloud.dcloud.net.cn/login">https://unicloud.dcloud.net.cn/login</a></strong></p>
</blockquote>
<ul>
<li><h2 id="创建uniCloud项目（uni-app官网，会详细一点）："><a href="#创建uniCloud项目（uni-app官网，会详细一点）：" class="headerlink" title="创建uniCloud项目（uni-app官网，会详细一点）："></a>创建uniCloud项目（uni-app官网，会详细一点）：</h2><ul>
<li><p>在创建新项目，选择uni-app项目，并勾选启动uniCloud</p>
</li>
<li><p>在右侧选择服务供应商（阿里云，腾讯云）</p>
</li>
<li><p>对于老的uni-app项目，也可以对项目点右键，菜单中选择‘创建uniCloud云开发环境’</p>
</li>
<li><p>新建uniapp项目中的模板，有一个hello uniCloud 项目模板，演示了各种云函数的使用。（创建了一个为cloudfunctions）</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/a8RQy3ZoFTMq.png" alt="新项目创建uniCloud项目"></p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/9ldIaqTO8WjH.png" alt="老项目创建uniCloud项目"></p>
</li>
</ul>
<hr>
</li>
<li><h2 id="创建和绑定服务空间-数据库和云函数-："><a href="#创建和绑定服务空间-数据库和云函数-：" class="headerlink" title="创建和绑定服务空间(数据库和云函数)："></a>创建和绑定服务空间(数据库和云函数)：</h2><ul>
<li><p>注：如果是只有一个服务空间的话，系统会帮我们绑定，要是多个的话，需要我们手动绑定一下。</p>
</li>
<li><p>项目创建好后，需要我们为这个项目创建一个服务空间（如果没有实名认证的话，首先需要实名认证）</p>
</li>
<li><p>在云函数目录cloudfunctions，右键菜单创建服务空间，会打开web控制台跳转进行创建</p>
</li>
<li><p>创建好服务空间后，对目录cloudfunctions，点击右键菜单中，选择云服务空间，点击你创建的服务空间</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/OvKi3l^BffVg.png"></p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/zgDNgtH25pNu.png"></p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/QuArHbNVEK2w.png"></p>
</li>
</ul>
<hr>
</li>
<li><h2 id="客户端-前端-调用云函数"><a href="#客户端-前端-调用云函数" class="headerlink" title="客户端(前端)调用云函数:"></a>客户端(前端)调用云函数:</h2><ul>
<li><p>前端代码（H5前端、App、小程序），不再执行uni.request联网，而是通过<code>uniCloud.callFunction</code>调用云函数，<code>callFunction</code>定义如下：</p>
<ul>
<li><p><strong>请求参数:</strong></p>
<table>
<thead>
<tr>
<th align="center">字段</th>
<th align="center">类型</th>
<th align="center">必填</th>
<th align="center">说明</th>
</tr>
</thead>
<tbody><tr>
<td align="center">name</td>
<td align="center">String</td>
<td align="center">是</td>
<td align="center">云函数名称</td>
</tr>
<tr>
<td align="center">data</td>
<td align="center">Object</td>
<td align="center">否</td>
<td align="center">客户端需要传递的参数</td>
</tr>
</tbody></table>
</li>
<li><p><strong>相应参数:</strong></p>
<table>
<thead>
<tr>
<th align="center">字段</th>
<th align="center">类型</th>
<th align="center">说明</th>
</tr>
</thead>
<tbody><tr>
<td align="center">result</td>
<td align="center">Object</td>
<td align="center">云函数执行结果</td>
</tr>
<tr>
<td align="center">requestId</td>
<td align="center">String</td>
<td align="center">请求序列号，用于错误排查</td>
</tr>
</tbody></table>
</li>
</ul>
</li>
<li><h4 id="示例代码"><a href="#示例代码" class="headerlink" title="示例代码:"></a>示例代码:</h4><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// promise方式</span></span><br><span class="line">uniCloud.callFunction(&#123;</span><br><span class="line">    name: <span class="string">&#x27;test&#x27;</span>,</span><br><span class="line">    data: &#123; <span class="attr">a</span>: <span class="number">1</span> &#125;</span><br><span class="line">  &#125;)</span><br><span class="line">  .then(<span class="function"><span class="params">res</span> =&gt;</span> &#123;&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// callback方式</span></span><br><span class="line">uniCloud.callFunction(&#123;</span><br><span class="line">    name: <span class="string">&#x27;test&#x27;</span>,</span><br><span class="line">    data: &#123; <span class="attr">a</span>: <span class="number">1</span> &#125;,</span><br><span class="line">    success()&#123;&#125;,</span><br><span class="line">    fail()&#123;&#125;,</span><br><span class="line">    complete()&#123;&#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

</li>
</ul>
<hr>
</li>
<li><h2 id="创建数据库内的数据表"><a href="#创建数据库内的数据表" class="headerlink" title="创建数据库内的数据表:"></a>创建数据库内的数据表:</h2><blockquote>
<p>一个<code>uniCloud</code>服务空间，有且只有一个数据库。一个数据库支持多个集合（表）。一个集合可以有多个记录。每个记录可以有多个字段。</p>
</blockquote>
<ul>
<li><h3 id="可以在uniCloud（后台）中直接创建："><a href="#可以在uniCloud（后台）中直接创建：" class="headerlink" title="可以在uniCloud（后台）中直接创建："></a>可以在<code>uniCloud（后台）</code>中直接创建：</h3><p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/hS3rdUZzicou.png" alt="uniCloud网页后台可视化创建云数据库"></p>
</li>
<li><h3 id="可以通过db-init-js的后台代码来创建集合-表"><a href="#可以通过db-init-js的后台代码来创建集合-表" class="headerlink" title="可以通过db_init.js的后台代码来创建集合(表):"></a>可以通过<code>db_init.js</code>的后台代码来创建集合(表):</h3><ul>
<li><p><code>uniCloud</code>提供了一个 JSON 格式的文档型数据库。顾名思义，数据库中的每条记录都是一个 JSON 格式的文档。</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/xgrCrgX5an@M.png" alt="通过db_init.js代码创建"></p>
</li>
<li><p>每个集合，其实包含3个部分：</p>
<ul>
<li><code>data</code>：<strong>数据内容</strong></li>
<li><code>index</code>：<strong>数据库索引</strong></li>
<li><code>schema</code>：<strong>数据表格式定义</strong></li>
</ul>
</li>
<li><p>在<code>uniCloud</code>的web控制台可以看到一个集合的3部分内容。</p>
</li>
<li><h4 id="数据内容（data）"><a href="#数据内容（data）" class="headerlink" title="数据内容（data）:"></a>数据内容（data）:</h4><ul>
<li><code>data</code>很简单，就是存放的数据记录<code>(record)</code>。</li>
<li>实际上，创建一条新记录，是不管在web控制台创建，还是通过API创建，每条记录都会自带一个<code>_id</code>字段用以作为该记录的<strong>唯一标志</strong>。</li>
<li><code>_id</code>字段是每个集合默认自带且不可删除的字段。同时，它也是<strong>集合的索引</strong>。</li>
</ul>
</li>
<li><h4 id="数据库索引（index）："><a href="#数据库索引（index）：" class="headerlink" title="数据库索引（index）："></a>数据库索引（index）：</h4><ul>
<li>所谓索引，<strong>是指在集合的众多字段中挑选一个或多个字段，让数据库引擎优先处理这些字段。设置为索引的字段，在通过该字段查询记录时可以获得更快的查询速度。</strong></li>
<li>一个集合可以有多个字段被设为索引。</li>
<li>索引分<strong>唯一型</strong>和<strong>非唯一型</strong>。</li>
<li><strong>唯一型索</strong>引要求整个集合多个记录的该字段的值<strong>不能重复</strong>。比如<code>_id</code>就是唯一型索引。</li>
<li>假使有2个人都叫“张三”，那么他们在user集合里的区分就是依靠不同的<code>_id</code>来区分。</li>
<li>如果我们要根据name字段来查询，为了提升查询速度，此时可以把name字段设为非唯一索引。</li>
<li>还有<strong>“组合索引”</strong>的概念，<strong>可以把多个字段组合成一个“组合索引”</strong>。例如一个文章点赞记录明细表，设置文章id和用户id为组合索引，且将此组合索引设为唯一型索引，就可以限制同一用户对一篇文章多次点赞。</li>
</ul>
</li>
<li><h4 id="代码"><a href="#代码" class="headerlink" title="代码:"></a>代码:</h4><figure class="highlight json"><table><tr><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">&quot;opendb-news-article&quot;</span>: &#123;   <span class="comment">//表名</span></span><br><span class="line">    <span class="attr">&quot;data&quot;</span>: [],</span><br><span class="line">    <span class="attr">&quot;index&quot;</span>:[&#123;</span><br><span class="line">      <span class="attr">&quot;IndexName&quot;</span>: <span class="string">&quot;user_article_&quot;</span>, <span class="comment">// 索引名称</span></span><br><span class="line">      <span class="attr">&quot;MgoKeySchema&quot;</span>: &#123; <span class="comment">// 索引规则</span></span><br><span class="line">          <span class="attr">&quot;MgoIndexKeys&quot;</span>: [&#123;</span><br><span class="line">              <span class="attr">&quot;Name&quot;</span>: <span class="string">&quot;user_id&quot;</span>, <span class="comment">// 索引字段</span></span><br><span class="line">              <span class="attr">&quot;Direction&quot;</span>: <span class="string">&quot;1&quot;</span> <span class="comment">// 索引方向，1：ASC-升序，-1：DESC-降序，2dsphere：地理位置</span></span><br><span class="line">          &#125;,&#123;</span><br><span class="line">              <span class="attr">&quot;Name&quot;</span>: <span class="string">&quot;article_id&quot;</span>, <span class="comment">// 索引字段</span></span><br><span class="line">              <span class="attr">&quot;Direction&quot;</span>: <span class="string">&quot;1&quot;</span> <span class="comment">// 索引方向，1：ASC-升序，-1：DESC-降序，2dsphere：地理位置</span></span><br><span class="line">          &#125;],</span><br><span class="line">          <span class="attr">&quot;MgoIsUnique&quot;</span>: <span class="literal">false</span> <span class="comment">// 索引是否唯一</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><h4 id="注意"><a href="#注意" class="headerlink" title="注意:"></a>注意:</h4><ol>
<li>如果记录中已经存在多个记录某字段相同的情况，那么将该字段设为唯一型索引会失败。</li>
<li>如果已经设置某字段为唯一索引，在新增和修改记录时如果该字段的值之前在其他记录已存在，会失败。</li>
<li>假如记录中不存在某个字段，则对索引字段来说其值默认为 null，如果该索引字段设为唯一型索引，则不允许存在两个或以上的该字段为null或不存在该字段的记录。</li>
<li>在uni-app中，为了安全起见，<strong>是不允许客户端直接调用数据库，而是通过客户端调用云函数</strong>，云函数调用数据库的形式。</li>
</ol>
</li>
</ul>
</li>
</ul>
<hr>
</li>
<li><h2 id="数据库和集合的引用"><a href="#数据库和集合的引用" class="headerlink" title="数据库和集合的引用:"></a>数据库和集合的引用:</h2><ul>
<li><p><strong>获取数据库对象和引用:</strong></p>
<ul>
<li><code>const db = uniCloud.database();</code></li>
</ul>
</li>
<li><p><strong>获取集合对象和引用:</strong></p>
<ul>
<li>通过 <code>db.collection(name)</code> 可以获取指定集合的引用。</li>
</ul>
</li>
<li><p><strong>代码:</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> db=uniCloud.database();</span><br><span class="line"><span class="keyword">const</span> ban=db.collection(<span class="string">&#x27;集合名&#x27;</span>);<span class="comment">//集合名就是数据表的名称</span></span><br><span class="line">db.createCollection(collectionName)<span class="comment">//创建集合</span></span><br></pre></td></tr></table></figure>

</li>
</ul>
<hr>
</li>
<li><h2 id="云数据库的使用（增、删、改、查）"><a href="#云数据库的使用（增、删、改、查）" class="headerlink" title="云数据库的使用（增、删、改、查）:"></a>云数据库的使用（增、删、改、查）:</h2><ul>
<li><p>通过 <code>db.collection(name)</code> 可以获取指定集合的引用，在集合上可以进行以下操作：</p>
<table>
<thead>
<tr>
<th align="center">类型</th>
<th align="center">接口</th>
<th align="center">说明</th>
</tr>
</thead>
<tbody><tr>
<td align="center">写</td>
<td align="center">add</td>
<td align="center">新增记录（触发请求）</td>
</tr>
<tr>
<td align="center">计数</td>
<td align="center">count</td>
<td align="center">获取符合条件的记录条数</td>
</tr>
<tr>
<td align="center">读</td>
<td align="center">get</td>
<td align="center">获取集合中的记录，如果有使用where语句定义查询条件，则会返回匹配结果集（触发请求）</td>
</tr>
<tr>
<td align="center">引用</td>
<td align="center">doc</td>
<td align="center">获取对集合中指定id的记录的引用</td>
</tr>
<tr>
<td align="center">查询条件</td>
<td align="center">where</td>
<td align="center">通过指定条件筛选出匹配的记录，可搭配查询指令（eq, gt , in,…）使用</td>
</tr>
<tr>
<td align="center"></td>
<td align="center">skip</td>
<td align="center">跳过指定数量的文档，常用于分页</td>
</tr>
<tr>
<td align="center"></td>
<td align="center">orderBy</td>
<td align="center">排序方式</td>
</tr>
<tr>
<td align="center"></td>
<td align="center">limit</td>
<td align="center">返回的结果集（文档数量）的限制，有默认值和上限值</td>
</tr>
<tr>
<td align="center"></td>
<td align="center">field</td>
<td align="center">指定需要返回的字段</td>
</tr>
</tbody></table>
</li>
<li><p><code>collection</code>对象的方法可以增和查数据，<strong>删和改不能直接操作</strong>，需要collection对象通过doc或get得到指定的记录后再调用<code>remove</code>或<code>update</code>方法进行删改。</p>
</li>
<li><h4 id="代码-1"><a href="#代码-1" class="headerlink" title="代码:"></a>代码:</h4><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">  <span class="keyword">const</span> db=uniCloud.database();</span><br><span class="line">  <span class="keyword">const</span> ban=db.collection(<span class="string">&#x27;集合名&#x27;</span>);</span><br><span class="line">  ban.get().then(<span class="function"><span class="params">res</span>=&gt;</span>&#123;<span class="built_in">console</span>.log(res)&#125;).catch(<span class="function"><span class="params">msg</span>=&gt;</span>&#123;<span class="built_in">console</span>.log(msg)&#125;);<span class="comment">//获取集合中的数据，promise写法</span></span><br><span class="line">  ban.get(&#123;<span class="attr">sucess</span>:<span class="function">(<span class="params">res</span>)=&gt;</span>&#123;<span class="built_in">console</span>.log(res)&#125;,<span class="attr">fail</span>:<span class="function">(<span class="params">msg</span>)=&gt;</span>&#123;<span class="built_in">console</span>.log(msg)&#125;&#125;);<span class="comment">//第二种写法</span></span><br><span class="line">  <span class="comment">//这里只简单的介绍，详细的可查看 官方文档</span></span><br><span class="line">  ban.where(&#123;<span class="comment">//查询</span></span><br><span class="line">    name:<span class="string">&quot;查询的name&quot;</span>，</span><br><span class="line">    index：查询的下标等  </span><br><span class="line">  &#125;).get().then(<span class="function"><span class="params">res</span>=&gt;</span>&#123;<span class="built_in">console</span>.log(res)&#125;).catch(<span class="function"><span class="params">e</span>=&gt;</span>&#123;<span class="built_in">console</span>.log(msg)&#125;);</span><br><span class="line">  <span class="comment">//添加</span></span><br><span class="line">  ban.add(&#123;</span><br><span class="line">    data:&#123;</span><br><span class="line">        id:要添加的id，</span><br><span class="line">        name：要添加的name</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;).then(<span class="function"><span class="params">res</span>=&gt;</span>&#123;<span class="built_in">console</span>.log(res)&#125;).catch(<span class="function"><span class="params">e</span>=&gt;</span>&#123;<span class="built_in">console</span>.log(msg)&#125;);</span><br><span class="line">  <span class="comment">//更新：局部更新（只能更新一条数据），全局更新（覆写）</span></span><br><span class="line">  ban.doc(<span class="string">&#x27;id&#x27;</span>).update(&#123;<span class="comment">//局部更新</span></span><br><span class="line">    data:&#123;</span><br><span class="line">      name:<span class="string">&#x27;要替换的属性名&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;).then(<span class="function"><span class="params">res</span>=&gt;</span>&#123;<span class="built_in">console</span>.log(res)&#125;).catch(<span class="function"><span class="params">e</span>=&gt;</span>&#123;<span class="built_in">console</span>.log(msg)&#125;);</span><br><span class="line">  ban.doc(<span class="string">&#x27;id&#x27;</span>).set(&#123;<span class="comment">//全局更新：相当于在重写数据</span></span><br><span class="line">    data:&#123;</span><br><span class="line">      name:<span class="string">&#x27;要替换的属性名&#x27;</span>，</span><br><span class="line">      id：要替换的id名</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;).then(<span class="function"><span class="params">res</span>=&gt;</span>&#123;<span class="built_in">console</span>.log(res)&#125;).catch(<span class="function"><span class="params">e</span>=&gt;</span>&#123;<span class="built_in">console</span>.log(msg)&#125;);</span><br><span class="line"><span class="comment">//删除数据，只能每次删除一条</span></span><br><span class="line">  ban.doc(<span class="string">&#x27;id&#x27;</span>).remove(&#123; &#125;).then(<span class="function"><span class="params">res</span>=&gt;</span>&#123;<span class="built_in">console</span>.log(res)&#125;).catch(<span class="function"><span class="params">e</span>=&gt;</span>&#123;<span class="built_in">console</span>.log(msg)&#125;);</span><br></pre></td></tr></table></figure>

</li>
</ul>
<hr>
</li>
<li><h2 id="云函数的创建"><a href="#云函数的创建" class="headerlink" title="云函数的创建:"></a>云函数的创建:</h2><ul>
<li><h4 id="客户端创建云函数（云函数调用数据库）："><a href="#客户端创建云函数（云函数调用数据库）：" class="headerlink" title="客户端创建云函数（云函数调用数据库）："></a>客户端创建云函数（云函数调用数据库）：</h4><ul>
<li><p>先新建一个云函数文件：</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/2TQF*jCRLI06.png" alt="新建云函数"></p>
</li>
</ul>
</li>
<li><h4 id="写云函数代码"><a href="#写云函数代码" class="headerlink" title="写云函数代码:"></a>写云函数代码:</h4><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="meta">&#x27;use strict&#x27;</span>;</span><br><span class="line"><span class="comment">//获取数据库对象</span></span><br><span class="line"><span class="keyword">const</span> db = uniCloud.database()</span><br><span class="line"><span class="comment">//获取表对象</span></span><br><span class="line"><span class="keyword">const</span> userInfoCollection = db.collection(<span class="string">&#x27;userInfo&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="built_in">exports</span>.main = <span class="keyword">async</span> (event, context) =&gt; &#123;</span><br><span class="line">    <span class="comment">//event为客户端上传的参数</span></span><br><span class="line">    <span class="keyword">let</span> &#123;account,password,mail,name,headImage,sex,date,detail&#125; = event</span><br><span class="line">    <span class="keyword">let</span> res = <span class="keyword">await</span> userInfoCollection.add(&#123;</span><br><span class="line">        account,password,mail,name,headImage,sex,date,detail</span><br><span class="line">    &#125;)</span><br><span class="line">    <span class="comment">//返回数据给客户端</span></span><br><span class="line">    <span class="keyword">return</span> res</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
</li>
<li><h4 id="上传并部署："><a href="#上传并部署：" class="headerlink" title="上传并部署："></a>上传并部署：</h4><ul>
<li><p>写完后点击右键，上传并部署：</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/n5YmI4^cusb0.png" alt="上传部署"></p>
</li>
</ul>
</li>
</ul>
<hr>
</li>
<li><h2 id="客户端调用云函数"><a href="#客户端调用云函数" class="headerlink" title="客户端调用云函数:"></a>客户端调用云函数:</h2><ul>
<li><h4 id="客户端动态传值并将数据添加到数据库中"><a href="#客户端动态传值并将数据添加到数据库中" class="headerlink" title="客户端动态传值并将数据添加到数据库中:"></a>客户端动态传值并将数据添加到数据库中:</h4><ul>
<li><p>云函数文件addUser–&gt;addUser.js</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="meta">&#x27;use strict&#x27;</span>;</span><br><span class="line"><span class="comment">//获取数据库对象</span></span><br><span class="line"><span class="keyword">const</span> db = uniCloud.database()</span><br><span class="line"><span class="comment">//获取表对象</span></span><br><span class="line"><span class="keyword">const</span> userInfoCollection = db.collection(<span class="string">&#x27;userInfo&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="built_in">exports</span>.main = <span class="keyword">async</span> (event, context) =&gt; &#123;</span><br><span class="line">    <span class="comment">//event为客户端上传的参数</span></span><br><span class="line">    <span class="keyword">let</span> &#123;account,password,mail,name,headImage,sex,date,detail&#125; = event</span><br><span class="line">    <span class="keyword">let</span> res = <span class="keyword">await</span> userInfoCollection.add(&#123;</span><br><span class="line">        account,password,mail,name,headImage,sex,date,detail</span><br><span class="line">    &#125;)</span><br><span class="line">    <span class="comment">//返回数据给客户端</span></span><br><span class="line">    <span class="keyword">return</span> res</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
</li>
<li><p>前端页面:</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">uniCloud.callFunction(&#123;</span><br><span class="line">        name: <span class="string">&#x27;addUser&#x27;</span>,</span><br><span class="line">        data: <span class="built_in">this</span>.userInfo,</span><br><span class="line">        success:<span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">                <span class="built_in">console</span>.log(res)</span><br><span class="line">                <span class="built_in">this</span>.active++;</span><br><span class="line">        &#125;,</span><br><span class="line">        fail:<span class="function">(<span class="params">err</span>) =&gt;</span> &#123;</span><br><span class="line">                uni.showModal(&#123;</span><br><span class="line">                    title: <span class="string">&#x27;错误&#x27;</span>,</span><br><span class="line">                    content: <span class="string">&#x27;邮箱或账号已被注册~~~&#x27;</span>,</span><br><span class="line">                    showCancel: <span class="literal">false</span>,</span><br><span class="line">                    success: <span class="function"><span class="keyword">function</span>(<span class="params">res</span>) </span>&#123;</span><br><span class="line">                            <span class="keyword">if</span> (res.confirm) &#123;</span><br><span class="line">                            </span><br><span class="line">                            &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;);</span><br><span class="line">        &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><h4 id="注"><a href="#注" class="headerlink" title="注:"></a>注:</h4><ul>
<li>此时云函数addUser中会添加该云函数的运行日志，数据库的对应表中会有添加对应的数据。</li>
<li>增删改查的写法都是一样的，详细的可以去看看官方的文档。</li>
</ul>
</li>
</ul>
</li>
</ul>
<hr>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">六根清静</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://liugenqingjing2.coding.me/2021/01/30/uniCloud%E4%BA%91%E5%BC%80%E5%8F%91%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/">https://liugenqingjing2.coding.me/2021/01/30/uniCloud云开发使用教程/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://liugenqingjing2.coding.me" target="_blank">小何blog (记录美好)</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/uniCloud/">uniCloud</a><a class="post-meta__tags" href="/tags/%E4%BA%91%E5%BC%80%E5%8F%91/">云开发</a></div><div class="post_share"><div class="social-share" data-image="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/Vx4Zi@ef8@Ro.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏<div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="http://qew58kkb2.hn-bkt.clouddn.com/wechat%20%20%281%29.png" target="_blank"><img class="post-qr-code-img" data-lazy-src="http://qew58kkb2.hn-bkt.clouddn.com/wechat%20%20%281%29.png" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li></ul></div></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2021/01/31/CSS3%E7%9F%A5%E8%AF%86%E8%A1%A5%E5%85%85%EF%BC%88%E4%BA%8C-%E9%A2%9C%E8%89%B2%E6%B8%90%E5%8F%98%EF%BC%89/"><img class="prev-cover" data-lazy-src="http://632500.haituie.cn/632500/v2-c8177ae4d610380b952b82172ce97f1e_r.jpg" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">CSS3知识补充（二.颜色渐变）</div></div></a></div><div class="next-post pull-right"><a href="/2021/01/30/uniCloud%E4%BA%91%E5%BC%80%E5%8F%91%E4%BB%8B%E7%BB%8D/"><img class="next-cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/kXUh5BKhimWl.jpg" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">uniCloud云开发介绍</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2021/01/30/uniCloud云开发介绍/" title="uniCloud云开发介绍"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210130/kXUh5BKhimWl.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-01-30</div><div class="title">uniCloud云开发介绍</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside_content" id="aside_content"><div class="card-widget card-info"><div class="card-content"><div class="card-info-avatar is-center"><img class="avatar-img" data-lazy-src="http://01.027cgb.com/632500/1576904533264.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">六根清静</div><div class="author-info__description">记录美好，记录生活，记录学习</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">138</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">63</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/he_chaoming/dashboard/projects?scope=public&amp;&amp;sort="><i class="fab fa-gofore"></i><span>My Gitee</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/he1213114428" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:484695754@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="tencent://message/?uin=484695754" target="_blank" title="QQ"><i class="fab fa-qq"></i></a></div></div></div><div class="card-widget card-recent-post"><div id="gamenews"><div class="card-content"><div class="item-headline"><i class="fas fa-cube"></i><span>ROLL资讯</span><i class="fas fa-retweet" @click="changetype(current)" style="float:right;margin-top:8px"></i></div><div class="newsbar"><span v-for="(type, index) in listtype" v-on:click="addClass(index)" v-bind:class="{ listtypeon:index==current}">{{type}}</span></div><div class="aside-list"><div class="aside-list-item" v-for="(news,index) in newsvue"><a class="thumbnail" href="javascript:void(0)" @click="getnewsdata(index)" :title="news.title"><img class="loaded" onerror="this.onerror=null;this.src='/img/404.jpg'" data-ll-status="loaded" :src="news.imgList[0]"/></a><div class="content"><a class="title" href="javascript:void(0)" @click="getnewsdata(index)" :title="news.title">{{news.title}}</a><time>{{news.postTime}}</time></div></div></div></div><div id="newsmodal"><button class="modalclose" @click="hidemodle()">关闭</button><h2>{{newpostvue.title}} </h2><h4>{{newpostvue.ptime}} &nbsp;&nbsp; {{newpostvue.source}}</h4><div v-html="newpostvue.content"></div></div></div></div><div class="card-widget card-shuo"><div class="card-content" style="height:auto;min-height:280px;"><div class="item-headline"><i class="fas fa-comments"></i><span>&#x8BF4;&#x8BF4</span><a id="shuovisualchange" style="cursor:pointer;float:right" onclick="shuovisualchange()">编辑</a></div><div id="artitalk_main" style="width:100%;height:100%;padding:10px"></div></div></div><div class="sticky_layout"></div><div class="card-widget card-history"><div class="card-content"><div class="item-headline"><i class="fas fa-paw fa-spin"></i><span>那年今日</span></div><div id="history-news" style="height: 100px;overflow: hidden;"><div id="history-card"></div></div></div></div><div class="card-widget card-announcement"><div class="card-content"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">大学生一枚，软件工程，想做全栈攻城狮，哈哈，有兴趣可以加 QQ:484695754 (也可以点上面的logo)，一起交流学习</div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="card-content"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#uniCloud%E4%BA%91%E5%BC%80%E5%8F%91%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B%EF%BC%9A"><span class="toc-number">1.</span> <span class="toc-text">uniCloud云开发使用教程：</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BAuniCloud%E9%A1%B9%E7%9B%AE%EF%BC%88uni-app%E5%AE%98%E7%BD%91%EF%BC%8C%E4%BC%9A%E8%AF%A6%E7%BB%86%E4%B8%80%E7%82%B9%EF%BC%89%EF%BC%9A"><span class="toc-number">1.1.</span> <span class="toc-text">创建uniCloud项目（uni-app官网，会详细一点）：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E5%92%8C%E7%BB%91%E5%AE%9A%E6%9C%8D%E5%8A%A1%E7%A9%BA%E9%97%B4-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8C%E4%BA%91%E5%87%BD%E6%95%B0-%EF%BC%9A"><span class="toc-number">1.2.</span> <span class="toc-text">创建和绑定服务空间(数据库和云函数)：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%A2%E6%88%B7%E7%AB%AF-%E5%89%8D%E7%AB%AF-%E8%B0%83%E7%94%A8%E4%BA%91%E5%87%BD%E6%95%B0"><span class="toc-number">1.3.</span> <span class="toc-text">客户端(前端)调用云函数:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%A4%BA%E4%BE%8B%E4%BB%A3%E7%A0%81"><span class="toc-number">1.3.0.1.</span> <span class="toc-text">示例代码:</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E5%BA%93%E5%86%85%E7%9A%84%E6%95%B0%E6%8D%AE%E8%A1%A8"><span class="toc-number">1.4.</span> <span class="toc-text">创建数据库内的数据表:</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%AF%E4%BB%A5%E5%9C%A8uniCloud%EF%BC%88%E5%90%8E%E5%8F%B0%EF%BC%89%E4%B8%AD%E7%9B%B4%E6%8E%A5%E5%88%9B%E5%BB%BA%EF%BC%9A"><span class="toc-number">1.4.1.</span> <span class="toc-text">可以在uniCloud（后台）中直接创建：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87db-init-js%E7%9A%84%E5%90%8E%E5%8F%B0%E4%BB%A3%E7%A0%81%E6%9D%A5%E5%88%9B%E5%BB%BA%E9%9B%86%E5%90%88-%E8%A1%A8"><span class="toc-number">1.4.2.</span> <span class="toc-text">可以通过db_init.js的后台代码来创建集合(表):</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%86%85%E5%AE%B9%EF%BC%88data%EF%BC%89"><span class="toc-number">1.4.2.1.</span> <span class="toc-text">数据内容（data）:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B4%A2%E5%BC%95%EF%BC%88index%EF%BC%89%EF%BC%9A"><span class="toc-number">1.4.2.2.</span> <span class="toc-text">数据库索引（index）：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81"><span class="toc-number">1.4.2.3.</span> <span class="toc-text">代码:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B3%A8%E6%84%8F"><span class="toc-number">1.4.2.4.</span> <span class="toc-text">注意:</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8C%E9%9B%86%E5%90%88%E7%9A%84%E5%BC%95%E7%94%A8"><span class="toc-number">1.5.</span> <span class="toc-text">数据库和集合的引用:</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%91%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84%E4%BD%BF%E7%94%A8%EF%BC%88%E5%A2%9E%E3%80%81%E5%88%A0%E3%80%81%E6%94%B9%E3%80%81%E6%9F%A5%EF%BC%89"><span class="toc-number">1.6.</span> <span class="toc-text">云数据库的使用（增、删、改、查）:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81-1"><span class="toc-number">1.6.0.1.</span> <span class="toc-text">代码:</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%91%E5%87%BD%E6%95%B0%E7%9A%84%E5%88%9B%E5%BB%BA"><span class="toc-number">1.7.</span> <span class="toc-text">云函数的创建:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%88%9B%E5%BB%BA%E4%BA%91%E5%87%BD%E6%95%B0%EF%BC%88%E4%BA%91%E5%87%BD%E6%95%B0%E8%B0%83%E7%94%A8%E6%95%B0%E6%8D%AE%E5%BA%93%EF%BC%89%EF%BC%9A"><span class="toc-number">1.7.0.1.</span> <span class="toc-text">客户端创建云函数（云函数调用数据库）：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%86%99%E4%BA%91%E5%87%BD%E6%95%B0%E4%BB%A3%E7%A0%81"><span class="toc-number">1.7.0.2.</span> <span class="toc-text">写云函数代码:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%8A%E4%BC%A0%E5%B9%B6%E9%83%A8%E7%BD%B2%EF%BC%9A"><span class="toc-number">1.7.0.3.</span> <span class="toc-text">上传并部署：</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%A2%E6%88%B7%E7%AB%AF%E8%B0%83%E7%94%A8%E4%BA%91%E5%87%BD%E6%95%B0"><span class="toc-number">1.8.</span> <span class="toc-text">客户端调用云函数:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%8A%A8%E6%80%81%E4%BC%A0%E5%80%BC%E5%B9%B6%E5%B0%86%E6%95%B0%E6%8D%AE%E6%B7%BB%E5%8A%A0%E5%88%B0%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD"><span class="toc-number">1.8.0.1.</span> <span class="toc-text">客户端动态传值并将数据添加到数据库中:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B3%A8"><span class="toc-number">1.8.0.2.</span> <span class="toc-text">注:</span></a></li></ol></li></ol></li></ol></li></ol></div></div></div><div class="card-widget card-recent-post"><div class="card-content"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2021/03/21/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%89-%E8%B7%A8%E5%9F%9F%E4%BB%8B%E7%BB%8D%E5%92%8CJSONP%E4%BB%8B%E7%BB%8D/" title="Node.js学习(二十三.跨域介绍和JSONP介绍)"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210321/qWPEashJOuNK.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十三.跨域介绍和JSONP介绍)"/></a><div class="content"><a class="title" href="/2021/03/21/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%89-%E8%B7%A8%E5%9F%9F%E4%BB%8B%E7%BB%8D%E5%92%8CJSONP%E4%BB%8B%E7%BB%8D/" title="Node.js学习(二十三.跨域介绍和JSONP介绍)">Node.js学习(二十三.跨域介绍和JSONP介绍)</a><time datetime="2021-03-21T13:40:58.000Z" title="发表于 2021-03-21 21:40:58">2021-03-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/20/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%BA%8C-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%8B/" title="Node.js学习(二十二.Node.js项目流程(下))"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210320/CvAoe6kC5*f2.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十二.Node.js项目流程(下))"/></a><div class="content"><a class="title" href="/2021/03/20/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%BA%8C-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%8B/" title="Node.js学习(二十二.Node.js项目流程(下))">Node.js学习(二十二.Node.js项目流程(下))</a><time datetime="2021-03-20T14:33:29.000Z" title="发表于 2021-03-20 22:33:29">2021-03-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/15/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%80-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%AD/" title="Node.js学习(二十一.Node.js项目流程(中))"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210320/gSrAfCznw@^F.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十一.Node.js项目流程(中))"/></a><div class="content"><a class="title" href="/2021/03/15/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%80-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%AD/" title="Node.js学习(二十一.Node.js项目流程(中))">Node.js学习(二十一.Node.js项目流程(中))</a><time datetime="2021-03-15T04:35:12.000Z" title="发表于 2021-03-15 12:35:12">2021-03-15</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/14/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B(%E4%B8%8A)/" title="Node.js学习(二十.Node.js项目流程(上))"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210320/UMp@B^akHmf8.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十.Node.js项目流程(上))"/></a><div class="content"><a class="title" href="/2021/03/14/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B(%E4%B8%8A)/" title="Node.js学习(二十.Node.js项目流程(上))">Node.js学习(二十.Node.js项目流程(上))</a><time datetime="2021-03-14T14:36:58.000Z" title="发表于 2021-03-14 22:36:58">2021-03-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/02/27/Node-js%E5%AD%A6%E4%B9%A0-%E5%8D%81%E4%B9%9D-%E5%B0%81%E8%A3%85%E6%93%8D%E4%BD%9C%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8CCSRF/" title="Node.js学习(十九.封装操作数据库和CSRF)"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210227/EcgLTE4WPOp^.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(十九.封装操作数据库和CSRF)"/></a><div class="content"><a class="title" href="/2021/02/27/Node-js%E5%AD%A6%E4%B9%A0-%E5%8D%81%E4%B9%9D-%E5%B0%81%E8%A3%85%E6%93%8D%E4%BD%9C%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8CCSRF/" title="Node.js学习(十九.封装操作数据库和CSRF)">Node.js学习(十九.封装操作数据库和CSRF)</a><time datetime="2021-02-27T13:20:18.000Z" title="发表于 2021-02-27 21:20:18">2021-02-27</time></div></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By 六根清静</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi,  welcome  to  my  <a  href="">blog</a>!</div><div class="icp"><a><img class="icp-icon" src="/img/icp.png" alt="ICP"/><span>豫ICP备2020025430号</span></a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="rightside.chat_btn"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module" defer></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><script async="async">var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> {preloader.endLoading()})
setTimeout(function(){preloader.endLoading();}, 50000);</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    let initData = {
      el: '#vcomment',
      appId: 'kW2ft895T235y7DxmyJmXX5X-MdYXbMMI',
      appKey: 'v0zBPCAdwiJ0xg4s4eSfusLD',
      placeholder: '建议使用QQ邮箱，评论头像采用QQ头像',
      avatar: 'monsterid',
      meta: 'nick,mail,link'.split(','),
      pageSize: '10',
      lang: 'zh-CN',
      recordIP: false,
      serverURLs: 'https://???????.api.lncldglobal.com',
      emojiCDN: '',
      emojiMaps: "",
      enableQQ: true,
      path: window.location.pathname,
      master: '1f76478c4ec918ffc6d50de6b68db531'.split(','),
      friends: '5c?????bfe6rfc72a????e268ad3819c,7c?????bfe65fc02a????e2????3919c'.split(','),
      tagMeta: '博主,小伙伴,访客'.split(',')
    }

    if (true) { 
      initData.requiredFields= ('nick,mail'.split(','))
    }
    
    if (false) {
      const otherData = false
      initData = Object.assign({}, initData, otherData)
    }
    
    const valine = new Valine(initData)
  }

  if (typeof Valine === 'function') initValine() 
  else $.getScript('https://cdn.jsdelivr.net/gh/HCLonely/Valine@latest/dist/Valine.min.js', initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.querySelector('#vcomment'),loadValine)
  else setTimeout(() => loadValine(), 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script src='https://cdn.jsdelivr.net/npm/artitalk'></script><script> $(".category-list-count").prepend("<i class=\"fas fa-book\"></i>");</script><script src="/js/list.js"></script><script src="/js/gitcalendar.js"></script><script src="/js/calendar.js"></script><script src="/js/xkTool.js"></script><script src="/js/pjax.js"></script><script src="/magnet/js/vue.min.js"></script><script src="/magnet/js/catalogMagnet.js"></script><script src="/js/airvisualapi.js"></script><script src="/js/history.js"></script><script src="/js/historyroll.js"></script><script src="/js/change.js"></script><script type="text/javascript" src="https://www.airvisual.com/scripts/widget_v2.0.js"></script><script> setTimeout(function(){$('.monoline').eq(0).html($(".monoline strong").eq(0).text().replace('°','℃'));},5000);</script><script src="https://cdn.jsdelivr.net/gh/sviptzk/HexoStaticFile@latest/Hexo/js/mouse_snow.min.js"></script><script src="/js/myBg.js"></script><script src="/js/shuo.js"></script><script src="/js/artitalkkey.js"></script><script src="/news/js/keys.js"></script><script src="/news/js/news.js"></script><script src="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/js/pool.min.js"><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/stars/stars.js"></script><script src="https://cdn1.lncld.net/static/js/3.5.0/av-min.js"></script><script src="/zan/zan.js"></script><div class="aplayer no-destroy" data-id="2916766519" data-server="netease" data-type="playlist" data-fixed="true" data-mini="true" data-listFolded="false" data-order="random" data-preload="none" data-autoplay="false" muted></div><script src="/swiper/swiper.min.js"></script><script src="/swiper/swiperindex.js"></script><script async src="//at.alicdn.com/t/font_2264842_3izu8i5eoc2.js"></script><canvas class="fireworks" mobile="false"></canvas><script src="/js/third-party/fireworks.js"></script><script src="/js/third-party/activate-power-mode.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script>(function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/6fdec148.js","daovoice")
</script><script>var isChatBtn = true
daovoice('init', {
  app_id: '6fdec148',},{
  launcher: { 
     disableLauncherIcon: isChatBtn // 悬浮 ICON 是否显示
  },
});
daovoice('update');

if (isChatBtn) {
  var chatBtnFn = () => {
    var chatBtn = document.getElementById("chat_btn")
    chatBtn.addEventListener("click", function(){
      daovoice('show')
    });
  }
  chatBtnFn()
} else {
  if (true) {
    function chatBtnHide () {
      daovoice('update', {},{
        launcher: { 
        disableLauncherIcon: true // 悬浮 ICON 是否显示
        },
      });
    }
    function chatBtnShow () {
      daovoice('update', {},{
        launcher: { 
        disableLauncherIcon: false // 悬浮 ICON 是否显示
        },
      });
    }
  }
}</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script></div><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"scale":1,"hHeadPos":0.5,"vHeadPos":0.618,"jsonPath":"/live2dw/assets/unitychan.model.json"},"display":{"superSample":2,"width":150,"height":300,"position":"right","hOffset":0,"vOffset":-20},"mobile":{"show":true,"scale":0.6},"react":{"opacityDefault":0.7,"opacityOnHover":0.8},"log":false});</script></body></html>